package org.gap.web.jsf;

import java.util.List;

import org.gap.dao.RelationsDAO;
import org.gap.dao.RelationsTiersDAO;

import org.gap.domain.Relations;
import org.gap.domain.RelationsTiers;

import org.gap.service.RelationsService;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.context.annotation.Scope;

import org.springframework.stereotype.Component;

import org.springframework.transaction.annotation.Transactional;

/**
 * Spring Component that handles CRUD requests for Relations entities
 * 
 */
@Scope("session")
@Component("RelationsComponent")
public class RelationsComponentImpl implements RelationsComponent {

	/**
	 * Data type variable that provides CRUD operations for Relations entities
	 * 
	 */
	private Relations relations;

	/**
	 * DAO injected by Spring that manages RelationsTiers entities
	 * 
	 */
	private RelationsTiers relationstierses;

	/**
	 * DAO injected by Spring that manages Relations entities
	 * 
	 */
	@Autowired
	private RelationsDAO relationsDAO;

	/**
	 * DAO injected by Spring that manages RelationsTiers entities
	 * 
	 */
	@Autowired
	private RelationsTiersDAO relationsTiersDAO;

	/**
	 * Service injected by Spring that provides CRUD operations for Relations entities
	 * 
	 */
	@Autowired
	private RelationsService relationsService;

	/** 
	 */
	public RelationsComponentImpl() {
	}

	/**
	 * Select an existing Relations entity
	 * 
	 */
	@Transactional
	public String selectRelations(String relRelationKey) {
		relations = relationsDAO.findRelationsByPrimaryKey(relRelationKey);

		return "/jsf/relations/viewRelations.xhtml";
	}

	/**
	 * Show all RelationsTiers entities by Relations
	 * 
	 */
	@Transactional
	public List<RelationsTiers> listRelationsRelationsTierses(String relRelationKey) {
		return new java.util.ArrayList<RelationsTiers>(relationsDAO.findRelationsByPrimaryKey(relRelationKey).getRelationsTierses());
	}

	/**
	 * Save an existing RelationsTiers entity
	 * 
	 */
	@Transactional
	public String saveRelationsRelationsTierses(String relations_relRelation, RelationsTiers relationstiers) {
		relations = relationsService.saveRelationsRelationsTierses(relations_relRelation, relationstiers);

		return "/jsf/relations/viewRelations.xhtml";
	}

	/**
	 * Delete an existing RelationsTiers entity
	 * 
	 */
	@Transactional
	public String deleteRelationsRelationsTierses(String relations_relRelation, Integer related_relationstierses_rltTiersParent, Integer related_relationstierses_rltTiersFils, String related_relationstierses_rltRelation) {
		relations = relationsService.deleteRelationsRelationsTierses(relations_relRelation, related_relationstierses_rltTiersParent, related_relationstierses_rltTiersFils, related_relationstierses_rltRelation);

		return "/jsf/relations/viewRelations.xhtml";
	}

	/**
	 * Edit an existing RelationsTiers entity
	 * 
	 */
	@Transactional
	public String editRelationsRelationsTierses(String relations_relRelation, Integer related_relationstierses_rltTiersParent, Integer related_relationstierses_rltTiersFils, String related_relationstierses_rltRelation) {
		relationstierses = relationsTiersDAO.findRelationsTiersByPrimaryKey(related_relationstierses_rltTiersParent, related_relationstierses_rltTiersFils, related_relationstierses_rltRelation, -1, -1);
		return "/jsf/relations/relationstierses/editRelationsTierses.xhtml";
	}

	/**
	 * Select the child RelationsTiers entity for display allowing the user to confirm that they would like to delete the entity
	 * 
	 */
	@Transactional
	public String confirmDeleteRelationsRelationsTierses(String relations_relRelation, Integer related_relationstierses_rltTiersParent, Integer related_relationstierses_rltTiersFils, String related_relationstierses_rltRelation) {
		relationstierses = relationsTiersDAO.findRelationsTiersByPrimaryKey(related_relationstierses_rltTiersParent, related_relationstierses_rltTiersFils, related_relationstierses_rltRelation);

		return "/jsf/relations/relationstierses/deleteRelationsTierses.xhtml";
	}

	/**
	 * Select the Relations entity for display allowing the user to confirm that they would like to delete the entity
	 * 
	 */
	@Transactional
	public String confirmDeleteRelations(String relRelationKey) {
		relations = relationsDAO.findRelationsByPrimaryKey(relRelationKey);

		return "/jsf/relations/deleteRelations.xhtml";
	}

	/**
	 * Save an existing Relations entity
	 * 
	 */
	@Transactional
	public String saveRelations(Relations relations) {
		relationsService.saveRelations(relations);
		return "/jsf/relations/listRelationss.xhtml";
	}

	/**
	 * Getter for variable Relations
	 * 
	 */
	@Transactional
	public Relations getRelations() {
		return relations;
	}

	/**
	 * Create a new Relations entity
	 * 
	 */
	@Transactional
	public String newRelations() {
		relations = new Relations();

		return "/jsf/relations/createRelations.xhtml";
	}

	/**
	 * Create a new RelationsTiers entity
	 * 
	 */
	@Transactional
	public String newRelationsRelationsTierses(String relations_relRelation) {
		relationstierses = new RelationsTiers();

		return "/jsf/relations/relationstierses/createRelationsTierses.xhtml";
	}

	/**
	 * Show all Relations entities
	 * 
	 */
	@Transactional
	public List<Relations> listRelationss() {
		return new java.util.ArrayList<Relations>(relationsService.loadRelationss());
	}

	/**
	 * View an existing RelationsTiers entity
	 * 
	 */
	@Transactional
	public String selectRelationsRelationsTierses(String relations_relRelation, Integer related_relationstierses_rltTiersParent, Integer related_relationstierses_rltTiersFils, String related_relationstierses_rltRelation) {
		relationstierses = relationsTiersDAO.findRelationsTiersByPrimaryKey(related_relationstierses_rltTiersParent, related_relationstierses_rltTiersFils, related_relationstierses_rltRelation, -1, -1);
		return "/jsf/relations/relationstierses/viewRelationsTierses.xhtml";
	}

	/**
	 * Delete an existing Relations entity
	 * 
	 */
	@Transactional
	public String deleteRelations(String relRelationKey) {
		Relations relations = relationsDAO.findRelationsByPrimaryKey(relRelationKey);
		relationsService.deleteRelations(relations);
		return "/jsf/relations/listRelationss.xhtml";
	}

	/**
	 * Edit an existing Relations entity
	 * 
	 */
	@Transactional
	public String editRelations(String relRelationKey) {
		relations = relationsDAO.findRelationsByPrimaryKey(relRelationKey);

		return "/jsf/relations/editRelations.xhtml";
	}

	/**
	 * Getter for variable Relations
	 * 
	 */
	@Transactional
	public RelationsTiers getRelationstierses() {
		return relationstierses;
	}

}
